<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>step 2_1</title>
</head>

<body>
    <div id="wp"></div>
    <script id="tpl" type="text/html">
        <p>${str}</p>
        <p>${str1}</p>
    </script>
    <script>
        function compile(template, data) {
            const ks = Object.keys(data);
            const vs = ks.map((k) => data[k]);
            const t = `return \`${template}\``;
            const f = new Function(...ks, t);
            return f(...vs);
        }

        const obj = {
            str: 'hello world',
            str1: 'hello world 1'
        }

        const html = document.getElementById('tpl').innerHTML;
        const tpl = compile(html, obj)
        document.getElementById('wp').innerHTML = tpl;
    </script>
</body>

</html>